export const mixin = {
	methods: {
		courseType(data) {
			let value = ''
			switch (data) {
				case 1:
					value = '初级'
					break;
				case 2:
					value = '中级'
					break;
				case 3:
					value = '高级'
					break;
			}
			return value
		},
		//关于课程观看人数
		courseNumber(value) {
			const newValue = ['', '', '']
			let fr = 1000
			let num = 3
			let text1 = ''
			let fm = 1
			while (value / fr >= 1) {
				fr *= 10
				num += 1
				// console.log('数字', value / fr, 'num:', num)
			}
			if (num <= 8) { // 万
				text1 = parseInt(num - 4) / 3 > 1 ? '千万' : 'W'
				// tslint:disable-next-line:no-shadowed-variable
				fm = text1 === 'W' ? 10000 : 10000000
				if (value % fm === 0) {
					newValue[0] = parseInt(value / fm) + ''
				} else {
					newValue[0] = parseFloat(value / fm).toFixed(1) + ''
				}
				newValue[1] = text1
			}
			if (value < 1000) {
				newValue[0] = value + ''
				newValue[1] = ''
			}
			return newValue.join('')
		},
		getHeight(headerSearch, homeTabs,content,title) {
			let tabsHeight = 0
			let swiperHeight = 0
			if (headerSearch) {
				// 获取元素高度
				let searchView = uni.createSelectorQuery().select(headerSearch)
				searchView.boundingClientRect(data => {
					tabsHeight += data.height
				}).exec()
			}
			if (homeTabs) {
				let tabsView = uni.createSelectorQuery().select(homeTabs)
				tabsView.boundingClientRect(data => {
					tabsHeight += data.height
				}).exec()
			}	if (content) {
				let contentView = uni.createSelectorQuery().select(content)
				contentView.boundingClientRect(data => {
					tabsHeight += data.height
				}).exec()
			}	if (title) {
				let titleView = uni.createSelectorQuery().select(title)
				titleView.boundingClientRect(data => {
					tabsHeight += data.height
				}).exec()
			}
			// 获取系统信息
			uni.getSystemInfo({
				success(res) {
					// 获取当前可视区高
					swiperHeight = res.windowHeight - tabsHeight
				}
			})
			return swiperHeight
		}
	}
}